//
//  HMEmoticonButton.swift
//  HMWeiBo
//
//  Created by Apple on 16/8/9.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class HMEmoticonButton: UIButton {

    var emoticon: HMEmoticon?{
    
        didSet{
            
            //                button.setTitle(emoticon.png, forState: UIControlState.Normal)
            
            // 问题: 只有图片名字不行,还需要图片所对应的包的路径
            // 注意: 在分析思路的时候一定要根据线索去查找,另外一定要把线索锁定住
            if let png = emoticon?.png ,path = emoticon?.path{
                
                // 拼接图片路径
                let imagePath = "\(path)/\(png)"
                
                self.setImage(UIImage(named: imagePath), forState: UIControlState.Normal)
            } else {
                
                
                self.setImage(nil, forState: UIControlState.Normal)
            }
            
            
            if let emoji = emoticon?.emoji {
                
                self.setTitle(emoji, forState: UIControlState.Normal)
                
            } else {
                
                self.setTitle(nil, forState: UIControlState.Normal)
                
            }
            
        }
        
    }

}

